export default {
  props: {
    show: {
      type: Boolean,
      value: false,
    },
  },
  data() {
    return {
      visible: this.show,
    }
  },
  watch: {
    show() {
      this.visible = this.show;
    },
  },
  methods: {
    onCancel(formName = "ruleForm") {
      this.resetForm(formName);
      this.$emit("update:show", false);
    },
    resetForm(formName = "ruleForm") {
      this.$refs[formName].resetFields();
    },
    submit(formName = "ruleForm") {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit("save-data", this.formData);
        } else {
          this.$message.error("数据有误,请按照格式要求重新填写");
          return false;
        }
      });
    },
  },
}